<template>
	<view class="phone-main" :style="{height: '100%'}">
		<view class="phone-main-search">
			<text class="iconfont iconsousuo"></text>
			<input class="phone-main-input" v-model="phoneVal" @input="searchClick"
				style="height:40px;line-height: 40px;padding-left: 40px;" type="text" placeholder="请输入要搜索的数据" />
		</view>
		<view class="phoneDirectory" style="background-color: white;">
			<phone-list style="width:100%" :phones="phones" :letter="letter" :scrollAnimationOFF="scrollAnimationOFF"
				@change="handlePhoneListIndex" @reset="handleReset" @handleClick="handleClick" :addBtn="addBtn" :addBtnTitle="addBtnTitle" @addContactsOpen="addContactsOpen">
			</phone-list>
			<!-- <phone-alphabet 
			:phones="phones"
			:phoneListIndex="phoneListIndex"
			@change="handleDatasetKey" 
			@scrollAnimationOFF="handleScrollAnimationOFF"
			@reset="handleReset"
			>
			</phone-alphabet> -->
		</view>
	</view>
</template>

<script>
	import phoneList from './phone-list.vue'
	import phoneAlphabet from './phone-alphabet.vue'

	export default {
		name: "phone-directory",
		components: {
			phoneList,
			phoneAlphabet
		},
		props: {
			phones: Object,
			default: false,
			addBtn: {
				type:Boolean,
				default: false
			},
			addBtnTitle: String,
		},
		data() {
			return {
				phoneVal: '',
				winHeight: 0,
				letter: 'A',
				scrollAnimationOFF: true,
				phoneListIndex: 'A',
				reset: true
			}
		},
		computed: {
			phonesEscape() {
				return escape(JSON.stringify(this.phones))
			}
		},
		mounted() {
			let windowHeight = uni.getSystemInfoSync().windowHeight

			// #ifndef APP-PLUS
			this.winHeight = windowHeight
			//#endif

			//#ifdef APP-PLUS
			this.winHeight = windowHeight - 56
			//#endif

			if (!this.phones) {
				uni.showToast({
					title: '没有数据',
					icon: "none",
					mask: false,
					duration: 1500
				})
			}
		},
		methods: {
			searchClick() {
				this.$emit('handleSearch', this.phoneVal)
			},
			handleClick(e) {
				this.$emit('paramClick', e)
			},
			handleDatasetKey(val) {
				this.letter = val
			},
			handleScrollAnimationOFF(val) {
				this.scrollAnimationOFF = val
			},
			handlePhoneListIndex(val) {
				if (this.reset) {
					this.phoneListIndex = val
				}
			},
			handleReset(val) {
				if (val) {
					this.letter = ''
				}
				this.reset = val
			},
			addContactsOpen(){
				this.$emit('addContactsOpen', {})
			}

		}
	}
</script>

<style>
	.phone-main {
		display: flex;
		flex-direction: column;
		overflow: hidden;
	}

	.phoneDirectory {
		display: flex;
		flex-direction: row;
	}

	.phone-main-search {
		background-color: #fff;
		padding: 10upx 20upx;
		border-bottom: 1px solid #e5e5e5;
	}

	.iconsousuo {
		position: absolute;
		font-size: 24px;
		line-height: 40px;
		left: 18px;
	}

	.phone-main-input {
		font-size: 28upx;
		border: 1px solid #e5e5e5;
		border-radius: 3px;
		padding: 10upx 20upx 10upx 20upx;
	}
</style>
